import React, { Component } from 'react';
import {Icon,Menu,Dropdown, Avatar} from 'antd'
import 'antd/dist/antd.css'
import { withRouter } from 'react-router-dom'
import docCookies from "../../../../api/docCookies"
import UserDefault from '../../../../source/user.png'

class LoginMenu extends Component {

    //跳转我的等级
    handleLevel=()=>{
        this.props.history.push('/user/level')
    }

    //跳转个人设置
    personSetting=()=>{
        this.props.history.push('/setting')
    }

    //退出登录
    exit=(boo)=>{
        localStorage.removeItem("token")
        docCookies.removeItem("__csrf");
        localStorage.removeItem("loginObj")

        this.props.history.push("/");
        window.location.reload(true);
    }

    render() {
        const menu = (
            <Menu>
                <Menu.Item style={{ paddingLeft:"10px",paddingRight:"30px" }} onClick={ ()=>this.handleLevel() }>
                    <Icon type="database" />
                    <span>我的等级</span>
                </Menu.Item>

                <Menu.Item style={{ paddingLeft:"10px",paddingRight:"30px" }} onClick={ ()=>this.personSetting() }>
                    <Icon type="setting" />
                    <span>个人设置</span>
                </Menu.Item>
                <Menu.Item style={{ paddingLeft:"10px",paddingRight:"30px" }} onClick={ ()=>this.exit(true) }>
                    <Icon type="logout" />
                    <span>退出</span>
                </Menu.Item>
            </Menu>
        )

        return (
            <div style={{ color:"#fff" }} className='login-menu'>
                <Dropdown overlay={menu}>
                  <span style={{ marginRight:"10px" }}>
                  {
                      'http://cyq.center:8000/'+JSON.parse(localStorage.getItem("loginObj")).portrait === 'http://cyq.center:8000/'
                          ?<Avatar size="large" src={UserDefault}/>
                          :<Avatar size="large" src={'http://cyq.center:8000/'+JSON.parse(localStorage.getItem("loginObj")).portrait}/>
                  }
                      <Icon type="caret-down" style={{ marginLeft:"10px" }} />
                  </span>
                </Dropdown>
            </div>
        )
    }
}

export default withRouter(LoginMenu)
